-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor function update_accessibility_nodes
#10911
Conversation
Haven't taken a closer look yet (I will when I can) but this looks really good! I definitely agree that this is far more readable and takes good advantage of the tools Rust gives us for avoiding things like this. Hope it get's merged soon! |
@JustAnotherCodemonkey when you get a chance, I'd appreciate your review on this :) With two approvals I can merge this in <3 |
@alice-i-cecile How do I do a review? I've never done this before and don't see a button. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, very satisfying change to see. The code appears to have been successfully refactored into a far more readable state by removing the intimidating indentation and by breaking smaller tasks into separate functions.
a negation was missed in this refactor: #11206 |
# Objective - Since #10911, example `button` crashes when clicking the button ``` thread 'main' panicked at .cargo/registry/src/index.crates.io-6f17d22bba15001f/accesskit_consumer-0.16.1/src/tree.rs:139:9: assertion `left == right` failed left: 1 right: 0 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace Encountered a panic in system `bevy_winit::accessibility::update_accessibility_nodes`! Encountered a panic in system `bevy_app::main_schedule::Main::run_main`! ``` ## Solution - Re-add lost negation
Objective
update_accessibility_nodes
is one of the most nested functions in the entire Bevy repository, with a maximum of 9 levels of indentations. This PR refactors it down to 3 levels of indentations, while improving readability on other fronts. The result is a function that is actually understandable at a first glance.PS: I read AccessKit's documentation, but I don't have experience with it. Therefore, naming of variables and subroutines may be a bit off.
PS2: I don't know if the test suite covers the functionality of this system, but since I've spent quite some time on it and the changes were simple, I'm pretty confident the refactor is functionally equivalent to the original.
Solution
I documented each change with a commit, but as a summary I did the following to reduce nesting:
if-let
blocks tolet-else
statements where appropriate to reduce rightward shiftupdate_adapter
update_adapter
into new functionsqueue_node_for_update
andadd_children_nodes
Note for reviewers: GitHub's diff viewer is not the greatest in showing horizontal code shifts, therefore you may want to use a different tool like VSCode to review some commits, especially the second one (anyway, that commit is very straightforward, despite changing many lines).